<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>收藏夹</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no">
    <meta name="renderer" content="webkit" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="renderer" content="webkit|ie-comp|ie-stand" />
    <link rel="shortcut icon" href="/favicon.ico" type="/image/x-icon">
    <link rel="apple-touch-icon-precomposed" href="">
    <link rel="stylesheet" href="../source/src/css/main.css"/>

</head>
<body class="shop-cart-body">
<!-- 商品列表 -->
<div class="shop-cart">
    <ul class="order-list" id="order-list">

    </ul>
    <div class="add-more-product">
        <a href="../index.html">
            <i></i>
        </a>
    </div>


    <!--提交订单-->
    <!--<div class="submit-order">
        <div class="wrap clearifx">
            <div class="pro-checkbox on fl">
                    <span class="check-all">
                        <input type="checkbox" id="checkbox-2-1" class="beautify-checkbox" />
                        <label for="checkbox-2-1"></label>全选
                    </span>
                <span class="total-box">
                        共计<span class="total-num">0</span>个商品
                    </span>
            </div>

            <input type="button" class="submit-btn fr" id="submit-order" value="提交订单">
        </div>
    </div>-->
    <!--/提交订单-->
</div>

<!--底部菜单-->
<div class="pub-nav">
    <ul>
        <li>
            <a href="../index.html">
                <div class="index pic"></div>
                <div class="txt">首页</div>
            </a>
        </li>
        <li>
            <a href="./shop_cart.html?v=210818">
                <div class="shopCart pic"></div>
                <div class="txt">购物车</div>
            </a>
        </li>
        <li class="on">
            <a href="./me.html">
                <div class="me pic"></div>
                <div class="txt">我</div>
            </a>
        </li>
    </ul>
</div>
<!--/底部菜单-->

<script id="order-list-tpl" type="text/html">
    {{each CollectLists as list i}}
    {{each list.ItemList as li k}}
    <li class="order-item clearfix diy-box" data-code="{{li.Code}}">
        <a href="shop_detail.html?number={{li.Code}}" class="clearfix diy-box">
            <!--<div class="check-state">
                <div class="ico">
                    <input type="checkbox" id="checkbox-{{i}}-{{k}}" class="beautify-checkbox" />
                    <label for="checkbox-{{i}}-{{k}}"></label>
                </div>
            </div>-->
            <div class="pro-inro flex-1 clearfix">
                <div class="pic fl">
                    <img src="{{li.Picture}}" alt="{{li.Name}}">
                </div>
                <div class="txt fl">
                    <h2>{{li.Name}}</h2>
                    <div class="other">
                        规格：{{li.Model}}
                    </div>
                </div>
            </div>
            <div class="btn-box">
                <a href="javascript:;" class="delete" title="删除" data-billNo="{{list.BillNo}}"></a>

                <!--数量-->
               <!-- <div class="change-num clearfix fl">
                    <div class="num_wrap clearfix fl" >
                        <i id="minus" class="minus minus_disabled fl"></i>
                        <input type="tel" value="{{li.Qty}}"  class="num buynum fl">
                        <i id="plus" class="plus fl"></i>
                    </div>
                </div>-->
                <!--/数量-->
            </div>
        </a>
    </li>
    {{/each}}
    {{/each}}
</script>

<script src="../source/plugin/zepto.min.js"></script>
<script src="../source/plugin/artTemplate.js"></script>
<script src="../source/src/js/common.js"></script>
<script>
    var init ={
        render:function(){
            var inJson ={
                "custcode":getCookie('CustCode'),
                "username":decodeURIComponent(getCookie('username')),
                "pageindex":1,
                "pagecount":5,
                "key":user.key,
                "account":user.account
            };

            $.ajax({
                url:apiUrl+'/GetCollectItems',
                type:'GET',
                data:{"json":JSON.stringify(inJson)},
                //dataType :'jsonp',
                success:function(datas){
                    console.log(datas)

                    var html = template('order-list-tpl', datas);
                    $('#order-list').html(html);
                },
                error:function(datas){
                    console.log(datas.msg)
                }
            });
        },
        submitOrder:function(){
            $('#submit-order').click(function(){
                var inJson = {
                    "CollectLists": [
                        {
                            "ItemList": [
                            ],
                            "CustNo": getCookie('CustCode'),
                            "EmpNo": getCookie('EmpCode'),
                            "key": user.key,
                            "account": user.account
                        }
                    ]
                };

                $('#order-list').find(':checked').each(function(i,v){
                    var $this = $(this).parents('li');
                    var currentList = inJson.OrderLists[0].ItemList;
                    var json={
                        Model:"",
                        Picture:"",
                        Price:0,
                        Total:0
                    };
                    json.Code = $this.attr("data-code");
                    json.Name=$this.find('h2').html();
                    json.Qty=$this.find('.buynum ').val();
                    currentList.push(json);
                });

                $.ajax({
                    url:apiUrl+'/SubmitOrderItems',
                    type:'GET',
                    data:{"json":JSON.stringify(inJson)},
                    //          dataType :'jsonp',
                    success:function(datas){
                        if(datas.Success==true){
                            show_error_tip({str:'订单编号'+datas.Msg+"提交成功"});
                        }
                    },
                    error:function(datas){
                        console.log(datas.msg)
                    }
                });


            });
        },
        deleteCollect:function(){
            $('#order-list').on('click','.delete',function(){
                var $this = $(this);
                var inJson ={
                    "BillNo":$this.attr('data-billNo'),
                        "account":user.account,
                        "key":user.key
                    }
                $.ajax({
                    url:apiUrl+'/DeleteCollectItems',
                    type:'GET',
                    data:{"json":JSON.stringify(inJson)},
                    //          dataType :'jsonp',
                    success:function(datas){
                        if(datas.Success==true){
                            $this.parents('li').remove();
                            //alert("删除收藏成功");
                            show_error_tip({str:'删除收藏成功'});
                        }
                    },
                    error:function(datas){
                        console.log(datas.msg)
                    }
                });
            });
        },
        init:function(){
            this.render();
            this.submitOrder();
            this.deleteCollect();
        }
    }

    init.init();






    var shopCart ={

    }

    $('.order-list').find('input[type=checkbox]').click(function(){
        getTotal(); //获取总数
    });

    $('.delete').on('click',function(){//删除
        $(this).parents('li').remove();
        getTotal(); //获取总数
    });

    $('.check-all').on('click',function(){
        var $this = $(this);
        checkbox = $this.find('input[type=checkbox]');
        if(checkbox.prop('checked')){
            $('.order-list').find('input[type=checkbox]').prop('checked',true);
        }else{
            $('.order-list').find('input[type=checkbox]').prop('checked',false);
        }
        getTotal(); //获取总数
    });

    $('.minus').on('click',function(){
        var $this = $(this);
        var numObj = $this.siblings('.num');
        var numVal = numObj.val()*1;
        numVal--;
        if(numVal<=1){
            numVal=1;
            $this.addClass('minus_disabled');
        }
        numObj.val(numVal);

        getTotal(); //获取总数
    });
    $('.plus').on('click',function(){
        var $this = $(this);
        var numObj = $this.siblings('.num');
        var numVal = numObj.val()*1;
        numVal++;
        if(numVal>1){
            $this.siblings('.minus').removeClass('minus_disabled');
        }
        if(numVal>=100){
            numVal=100;
        }
        numObj.val(numVal);

        getTotal(); //获取总数
    });

    function getTotal(){//计算总数量和总价格
        var orderList = $('.order-list');
        var total = 0;
        orderList.find(':checked').each(function(i){
            var $this=$(this);
            total += $this.parents('li').find('.buynum').val()*1;
        });

        $('.total-num').html(total);
        return total;
    }
</script>
</body>
</html>